package com.example.textcode;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ButtonTest extends Activity
{
	private Button btn1;
	private Button btn2;

	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		btn1 = new Button(this);
		btn2 = new Button(this);
		btn1.setText("按钮1");
		btn2.setText("按钮2");
		btn1.setOnClickListener(new Onclick());
		btn2.setOnClickListener(new Onclick());
		setContentView(btn1);
		setContentView(btn2);
	}

	@SuppressLint({ "ShowToast", "ShowToast" })
	private class Onclick implements OnClickListener
	{

		@Override
		public void onClick(View view)
		{
			Button btn = (Button) view;
			if(btn==btn1)
			{
				Toast.makeText(getApplicationContext(), "点击的是按钮1",
						Toast.LENGTH_SHORT);
			}
			else if(btn==btn2)
			{
				Toast.makeText(getApplicationContext(), "点击的是按钮2",
						Toast.LENGTH_LONG);
				finish();
			}
		}

	}

}
